#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/dhcp.h"
#include "ethernetif.h"
#include "main.h"
#include "netconf.h"
#include "tcpip.h"
//#include "flash_info.h"
#include "eth_hal.h"





struct netif xnetif;
extern __IO uint32_t  EthStatus;



/**
  * @brief  Initializes the lwIP stack
  * @param  None
  * @retval None
  */
void LwIP_Init(void)
{
	struct ip_addr ipaddr;
	struct ip_addr netmask;
	struct ip_addr gw;

	tcpip_init( NULL, NULL );

//	uint8_t buf[4];
//	getLocalIP(buf);
//	IP4_ADDR(&ipaddr, buf[0], buf[1], buf[2], buf[3]);
//	DZ_printf("  Static IP address  %d.%d.%d.%d\r\n", buf[0], buf[1], buf[2], buf[3]);
//	getNetmask(buf);
//	IP4_ADDR(&netmask, buf[0], buf[1], buf[2], buf[3]);
//	getGw(buf);
//	IP4_ADDR(&gw, buf[0], buf[1], buf[2], buf[3]);
	
	IP4_ADDR(&ipaddr, 192, 168, 2, 179);
	IP4_ADDR(&netmask, 255, 255, 255, 0);
	IP4_ADDR(&gw, 192, 168, 2, 1);

  /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
            struct ip_addr *netmask, struct ip_addr *gw,
            void *state, err_t (* init)(struct netif *netif),
            err_t (* input)(struct pbuf *p, struct netif *netif))
    
   Adds your network interface to the netif_list. Allocate a struct
  netif and pass a pointer to this structure as the first argument.
  Give pointers to cleared ip_addr structures when using DHCP,
  or fill them with sane numbers otherwise. The state pointer may be NULL.

  The init function pointer must point to a initialization function for
  your ethernet netif interface. The following code illustrates it's use.*/

	netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);

	/* Registers the default network interface. */
	netif_set_default(&xnetif);

	if(EthStatus == (ETH_INIT_FLAG | ETH_LINK_FLAG))
	{
		xnetif.flags |= NETIF_FLAG_LINK_UP;
		netif_set_up(&xnetif);
	}
	else
	{
		netif_set_down(&xnetif);
	}
	netif_set_link_callback(&xnetif, ETH_link_callback);
}




/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
